/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package Beans;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

/**
 *
 * @author Thiago
 */
@Entity
@Table(name = "compra", catalog = "trust", schema = "")
/*
@NamedQueries({
    @NamedQuery(name = "Compra.findAll", query = "SELECT c FROM Compra c"),
    @NamedQuery(name = "Compra.findByIdCompra", query = "SELECT c FROM Compra c WHERE c.idCompra = :idCompra"),
    @NamedQuery(name = "Compra.findByDataCompra", query = "SELECT c FROM Compra c WHERE c.dataCompra = :dataCompra"),
    @NamedQuery(name = "Compra.findByTotalCompra", query = "SELECT c FROM Compra c WHERE c.totalCompra = :totalCompra"),
    @NamedQuery(name = "Compra.findByTotalParcelasCompra", query = "SELECT c FROM Compra c WHERE c.totalParcelasCompra = :totalParcelasCompra"),
    @NamedQuery(name = "Compra.findByStatusCompra", query = "SELECT c FROM Compra c WHERE c.statusCompra = :statusCompra"),
    @NamedQuery(name = "Compra.findByDescontoPercCompra", query = "SELECT c FROM Compra c WHERE c.descontoPercCompra = :descontoPercCompra"),
    @NamedQuery(name = "Compra.findByDescontoRealCompra", query = "SELECT c FROM Compra c WHERE c.descontoRealCompra = :descontoRealCompra"),        
    @NamedQuery(name = "Compra.findByFormaPgto", query = "SELECT c FROM Compra c WHERE c.formaPgto = :formaPgto")})
*/

public class Compra implements Serializable {
    @Transient
    private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "idCompra")
    private Integer idCompra;
    @Basic(optional = false)
    @Column(name = "dataCompra")
    @Temporal(TemporalType.DATE)
    private Date dataCompra;
    @Basic(optional = false)
    @Column(name = "totalCompra")
    private double totalCompra;
    @Basic(optional = false)
    @Column(name = "totalParcelasCompra")
    private int totalParcelasCompra;
    @Basic(optional = false)
    @Column(name = "statusCompra")
    private String statusCompra;
    @Basic(optional = false)
    @Column(name = "descontoPercCompra")
    private int descontoPercCompra;
    @Basic(optional = false)
    @Column(name = "descontoRealCompra")
    private double descontoRealCompra;    
    
    @ManyToOne
    @JoinColumn(name = "idcliente")
    private Cliente cliente;   
    
    @Basic(optional = false)   
    @ManyToOne
    @JoinColumn(name = "idformaPgto")
    private Formapgto formaPgto;
    
    @OneToMany(mappedBy = "compra")
    private List<Parcela> parcelas = new ArrayList<>();
    
    

    public Compra() {
    }

    public Compra(Integer idCompra) {
        this.idCompra = idCompra;
    }

    public Compra(Integer idCompra, Date dataCompra, double totalCompra, int totalParcelasCompra, String statusCompra, int descontoPercCompra, double descontoRealCompra, Formapgto formaPgto, Cliente cliente, List<Parcela> parcelas) {
        this.idCompra = idCompra;
        this.dataCompra = dataCompra;
        this.totalCompra = totalCompra;
        this.totalParcelasCompra = totalParcelasCompra;
        this.statusCompra = statusCompra;
        this.descontoPercCompra = descontoPercCompra;
        this.descontoRealCompra = descontoRealCompra;        
        this.formaPgto = formaPgto;
        this.cliente = cliente;
        this.parcelas = parcelas;
    }

    public Integer getIdCompra() {
        return idCompra;
    }

    public void setIdCompra(Integer idCompra) {
        Integer oldIdCompra = this.idCompra;
        this.idCompra = idCompra;
        changeSupport.firePropertyChange("idCompra", oldIdCompra, idCompra);
    }

    public Date getDataCompra() {
        return dataCompra;
    }

    public void setDataCompra(Date dataCompra) {
        Date oldDataCompra = this.dataCompra;
        this.dataCompra = dataCompra;
        changeSupport.firePropertyChange("dataCompra", oldDataCompra, dataCompra);
    }

    public double getTotalCompra() {
        return totalCompra;
    }

    public void setTotalCompra(double totalCompra) {
        double oldTotalCompra = this.totalCompra;
        this.totalCompra = totalCompra;
        changeSupport.firePropertyChange("totalCompra", oldTotalCompra, totalCompra);
    }

    public int getTotalParcelasCompra() {
        return totalParcelasCompra;
    }

    public void setTotalParcelasCompra(int totalParcelasCompra) {
        int oldTotalParcelasCompra = this.totalParcelasCompra;
        this.totalParcelasCompra = totalParcelasCompra;
        changeSupport.firePropertyChange("totalParcelasCompra", oldTotalParcelasCompra, totalParcelasCompra);
    }

    public String getStatusCompra() {
        return statusCompra;
    }

    public void setStatusCompra(String statusCompra) {
        String oldStatusCompra = this.statusCompra;
        this.statusCompra = statusCompra;
        changeSupport.firePropertyChange("statusCompra", oldStatusCompra, statusCompra);
    }

    public int getDescontoPercCompra() {
        return descontoPercCompra;
    }

    public void setDescontoPercCompra(int descontoPercCompra) {
        int oldDescontoPercCompra = this.descontoPercCompra;
        this.descontoPercCompra = descontoPercCompra;
        changeSupport.firePropertyChange("descontoPercCompra", oldDescontoPercCompra, descontoPercCompra);
    }

    public double getDescontoRealCompra() {
        return descontoRealCompra;
    }

    public void setDescontoRealCompra(double descontoRealCompra) {
        double oldDescontoRealCompra = this.descontoRealCompra;
        this.descontoRealCompra = descontoRealCompra;
        changeSupport.firePropertyChange("descontoRealCompra", oldDescontoRealCompra, descontoRealCompra);
    }

    

    

    public Formapgto geformaPgto() {
        return formaPgto;
    }

    public void setFormaPgto(Formapgto formaPgto) {
        Formapgto oldFormapgto = this.formaPgto;
        this.formaPgto = formaPgto;
        changeSupport.firePropertyChange("formaPgto", oldFormapgto, formaPgto);
    }
    
    public Cliente getCliente() {
        return cliente;
    }

    public void setCliente(Cliente cliente) {
        Cliente oldCliente = this.cliente;
        this.cliente = cliente;
        changeSupport.firePropertyChange("cliente", oldCliente, cliente);
    }
    
     public List<Parcela> getParcelas() {
        return parcelas;
    }

    public void setParcela(List<Parcela> parcelas) {
        List<Parcela> oldParcela =  this.parcelas;
        this.parcelas = parcelas;
        changeSupport.firePropertyChange("parcelas", oldParcela, parcelas);
    }
    
    
    
    

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idCompra != null ? idCompra.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Compra)) {
            return false;
        }
        Compra other = (Compra) object;
        if ((this.idCompra == null && other.idCompra != null) || (this.idCompra != null && !this.idCompra.equals(other.idCompra))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "View.Compra[ idCompra=" + idCompra + " ]";
    }

    public void addPropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.removePropertyChangeListener(listener);
    }
    
}
